package GinRouter

import "github.com/gin-gonic/gin"

type GroupRouter struct {
	GinEngine *gin.Engine
	Path string
	router *gin.RouterGroup
}

func (instance *GroupRouter) SetRouter(router *gin.RouterGroup) {
	instance.router = router
}

func (instance GroupRouter) GetEngine() *gin.Engine {
	return instance.GinEngine
}

func (instance *GroupRouter) InitRouter() {
	instance.router = instance.GinEngine.Group(instance.Path)
}

func (instance GroupRouter) Get(relativePath string, respCallback RespCallback) {
	instance.router.GET(relativePath, func(ctx *gin.Context) {
		defer ErrorHandler(ctx)
		respCallback(ctx)
	})
}

func (instance GroupRouter) Post(relativePath string, respCallback RespCallback) {
	instance.router.POST(relativePath, func(ctx *gin.Context) {
		defer ErrorHandler(ctx)
		respCallback(ctx)
	})
}

func (instance GroupRouter) Put(relativePath string, respCallback RespCallback) {
	instance.router.PUT(relativePath, func(ctx *gin.Context) {
		defer ErrorHandler(ctx)
		respCallback(ctx)
	})
}

func (instance GroupRouter) Delete(relativePath string, respCallback RespCallback) {
	instance.router.DELETE(relativePath, func(ctx *gin.Context) {
		defer ErrorHandler(ctx)
		respCallback(ctx)
	})
}
